<template>
<div>
  <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="学号" prop="username">
      <el-input v-model.number="ruleForm.username"></el-input>
    </el-form-item>
    <el-form-item label="昵称" prop="nick">
      <el-input v-model.number="ruleForm.nick"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="确认密码" prop="checkpassword">
      <el-input type="password" v-model="ruleForm.checkpassword" autocomplete="off"></el-input>
    </el-form-item>
    <el-row :gutter="2">
      <el-col :span="18">
        <div class="grid-content bg-purple">
          <el-form-item label="邮箱" prop="mail">
            <el-input v-model.number="ruleForm.mail" ></el-input>
          </el-form-item>
        </div>
      </el-col>
      <el-col :span="2">
        <div class="grid-content bg-purple">
          <el-button type="success" plain style="float: left">发送邮件</el-button>
        </div>
      </el-col>
    </el-row>
    <el-form-item label="邮箱验证码" prop="vercode" >
      <el-input v-model.number="ruleForm.vercode"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button class="" type="primary" style="width:70%;float: left" @click="submitForm('ruleForm')">注册</el-button>
    </el-form-item>
  </el-form>

</div>
</template>

<script>
export default {
  name: "registered",
  data() {
    var validatepassword2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.ruleForm.password) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        password: '',
        checkpassword: '',
        vercode: '',
        username: '',
        nick:'',
        mail:''
      },
      rules: {
        password: [
          { required: true, trigger: 'blur', message: '密码不能为空' }
        ],
        checkpassword: [
          { required: true,validator: validatepassword2, trigger: 'blur' }
        ],
        vercode: [
          { required: true, message: '请输入邮箱验证码', trigger: 'blur' }
        ],
        username: [
          { required: true, trigger: 'blur', message: '用户名不能为空' },
          { type: 'number', message: '请输入数字', trigger: ['blur', 'change'] }
        ],
        nick: [
          { required: true, trigger: 'blur', message: '昵称不能为空' }
        ],
        mail: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  }
}
</script>

<style scoped>
.el-row {

  margin-bottom: 20px;
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #fff;
}
.bg-purple {
  background: #ffffff;
}
.bg-purple-light {
  background: #ffffff;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #ffffff;
}
</style>
